/**
 * MIT License
 *
 * Copyright (C) 2023 Huawei Device Co., Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANT KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import React, {useEffect, useState} from 'react';
import {
  StyleSheet,
  Text,
  ScrollView,
  Button,
  View,
  TextInput,
  Platform
} from 'react-native';
import Clipboard, {useClipboard} from "@react-native-clipboard/clipboard";
// import {// HMLog} from "./Log";

// Small icon of a plus for demo purposes
const TEST_IMAGE =
  'iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg==';


function DateTimePickerDemo () {
  const scrollRef = React.useRef<ScrollView>(null);
  const[textResult, setTextResult] = useState('');
  //   const[text, setText] = useState('');
//   const[isURL, setIsURL] = useState(false);
//   const[data, setString] = useClipboard();
//   const[image, setImage] = useState(null);
//   const[imageString, setImageString] = useState<string>('');


const demoSetString = async (content: string) => {
    // HMLog('demoSetString fun enter:'+ content)
    Clipboard.setString(content)
    setTextResult("setString end:void")
    // HMLog('demoSetString fun end')
};

const demoGetString = async () => {
    // HMLog('demoGetString fun')
    let str = await  Clipboard.getString()
    setTextResult("demoGetString end:"+str)
    // HMLog('demoGetString, getString out:'+ str)
};


const demoSetStrings = async () => {
    // HMLog('demoSetStrings fun enter')
    // setStrings
    Clipboard.setStrings(["ABC100","ABC200","ABC300"])
    setTextResult("demoSetStrings end:void")
    // HMLog('demoSetStrings fun end')
};

const demoGetStrings = async () => {
    // HMLog('demoGetStrings fun enter')
    let array = await  Clipboard.getStrings()
    setTextResult("demoGetStrings end:"+JSON.stringify(array))
    // HMLog('demoGetStrings array out:'+ JSON.stringify(array))
    // HMLog('demoGetStrings fun end')
};

// --getString: () => Promise<string>;
// --getStrings: () => Promise<string[]>;
// --setString: (content: string) => void;
// hasString: () => Promise<boolean>;
// hasNumber: () => Promise<boolean>;

// getImagePNG: () => Promise<string>;
// getImageJPG: () => Promise<string>;
// setImage: (content: string) => void;
// getImage: () => Promise<string>;
// hasImage: () => Promise<boolean>;

// --setStrings: (content: string[]) => void;
// hasURL: () => Promise<boolean>;
// hasWebURL: () => Promise<boolean>;

const demoHasString = async () => {
    // HMLog('demoHasString fun enter')
    let flag = await  Clipboard.hasString()
    setTextResult("demoHasString end:"+flag)
    // HMLog('demoHasString fun out:'+ flag)
    // HMLog('demoHasString fun end')
};

const demoHasNumber = async () => {
    // HMLog('demoHasNumber fun enter')
    let flag = await  Clipboard.hasNumber()
    setTextResult("demoHasNumber end:"+flag)
    // HMLog('demoHasNumber fun out:'+ flag)
    // HMLog('demoHasNumber fun end')
};

const demoHasWebURL = async () => {
    // HMLog('demoHasWebURL fun enter')
    let flag = await  Clipboard.hasWebURL()
    setTextResult("demoHasWebURL end:"+flag)
    // HMLog('demoHasWebURL fun out:'+ flag)
    // HMLog('demoHasWebURL fun end')
};

const demoHasURL = async () => {
    // HMLog('demoHasURL fun enter')
    let flag = await  Clipboard.hasURL()
    setTextResult("hasURL end:"+flag)
    // HMLog('demoHasURL fun out:'+ flag)
    // HMLog('demoHasURL fun end')
};

const demoSetImage = (content: string) => {
    // HMLog('demoSetImage fun enter')
    Clipboard.setImage(content)
    setTextResult("setImage end:void")
    // HMLog('demoSetImage fun end')
};

const demoGetImage = async () => {
    // HMLog('demoGetImage fun enter')
    let strResult = await  Clipboard.getImage()
    setTextResult("demoGetImage end:"+strResult)
    // HMLog('demoGetImage fun string out:'+ strResult)
    // HMLog('demoGetImage fun end')
};

const demoHasImage = async () => {
    // HMLog('demoHasImage fun enter')
    let flag = await  Clipboard.hasImage()
    setTextResult("demoHasImage end:"+flag)
    // HMLog('demoHasImage fun out:'+ flag)
    // HMLog('demoHasImage fun end')
};

return (
  <ScrollView style={styles.container_100} ref={scrollRef}>
    <Text style={styles.header}>Clipboard Module</Text>
    <Text style={styles.boldText}>方法结果:</Text>

    <View style={ styles.flex_row_auto} >
    <Text style={{minHeight:30,
                 flex:1,
                 fontSize:16,
                 paddingLeft:8,
                 textAlign:'left'
                 }}>{textResult}</Text>
    </View>
    <Text style={styles.boldText}>说明:软键盘回车调用方法 </Text>

    <View style={ styles.flex_row_auto} >
       <Text style={{minHeight:30,
                 flex:1,
                 fontSize:16,
                 textAlign:'left'
                 }}>setNum:</Text>

      <TextInput style={ styles.flex_input} 
                 defaultValue={'1'} 
                 onSubmitEditing={ (value)=>{
                     demoGetString(value.nativeEvent.text)
                 }}/>
                 
    </View>
    <View style={ styles.flex_row_auto} >
       <Text style={{minHeight:30,
                 flex:1,
                 fontSize:16,
                 textAlign:'left'
                 }}>setString:</Text>

      <TextInput style={ styles.flex_input} 
                 defaultValue={'nr11'} 
                 onSubmitEditing={ (value)=>{
                     demoGetString(value.nativeEvent.text)
                 }}/>
                 
    </View>
    <View style={ styles.flex_row_auto} >
       <Text style={{minHeight:30,
                 flex:1,
                 fontSize:16,
                 textAlign:'left'
                 }}>setString:</Text>

      <TextInput style={ styles.flex_input} 
                 defaultValue={'www.baidu.com'} 
                 onSubmitEditing={ (value)=>{
                    //  demoGetString(value.nativeEvent.text)
                 }}/>
    </View>

    <Button onPress={()=>{ demoSetString("dataability:///com.example.myapplication1/user.txt")} } title="mock setURL" />
    <Button onPress={ demoGetString} title="getString (async)" />  

    <Button style={{marginTop:10}} onPress={ demoSetStrings}  title="demoSetStrings" /> 
    <Button style={{marginTop:10}} onPress={ demoGetStrings}  title="demoGetStrings(async)" /> 

    <Button style={{marginTop:20}} onPress={ demoHasString}  title="hasString(async)" /> 
    <Button style={{marginTop:20}} onPress={ demoHasNumber}  title="hasNumber(async)" /> 
    <Button style={{marginTop:20}} onPress={ demoHasURL}  title="hasURL(async)" /> 
    <Button style={{marginTop:20}} onPress={ demoHasWebURL}  title="hasWebURL(async)" /> 
    <Button style={{marginTop:20}} onPress={ demoHasImage}  title="hasImage(async)" /> 

    </ScrollView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
  },
  container_100: {
    paddingTop:Platform.OS==='ios'?50:0,
   width:'100%',
   height:'100%',
  },
  main: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  header: {
    fontWeight: '700',
    fontSize: 30,
    marginBottom: 10,
  },
  boldText: {
    fontWeight: '600',
    marginBottom: 10,
  },
  flex_row_auto:{
     flexDirection:"row",
     minHeight:50,
     paddingLeft:10,
     paddingRight:10
  },
  flex_input:{
    minHeight:30,
    flex:1,
    fontSize:14,
    borderWidth:1
  },
  separator: {
    height: StyleSheet.hairlineWidth,
    backgroundColor: 'gray',
    width: '80%',
    marginVertical: 20,
  },
  textInput: {
    borderColor: 'gray',
    borderWidth: 1,
    width: '80%',
    paddingHorizontal: 80,
    paddingVertical: 8,
    marginBottom: 16,
  },
  textInputMacOS: {
    borderColor: 'gray',
    borderWidth: StyleSheet.hairlineWidth,
    width: 300,
    padding: 4,
    marginBottom: 16,
  },
  clipboardContent: {
    marginBottom: 20,
  },
  imageContent: {
    width: 40,
    height: 40,
  },
  imageAndroid: {
    height: 160,
    width: 160,
  },
  imageButtonAndroid: {
    marginTop: 10,
  },
});


export default DateTimePickerDemo;